// JavaScript Document

// for auto-compute the summary result table, if the table is less than the input height, the div will only set same height as table.
function setSummaryDivHeight(divId, tableId, maxHeight){
	var layer = document.getElementById(divId);
	var resultTable = document.getElementById(tableId);
	var h = parseInt(resultTable.offsetHeight);
	layer.style.height = h+6 >maxHeight ? maxHeight : h+6;
	layer.style.overflow = "auto";
	return;
}


function setSummaryDivHeightViaScreen(divId, tableId, percentage){
	var layer = document.getElementById(divId);
	var resultTable = document.getElementById(tableId);
	var screenH = parseInt(document.body.clientHeight);
	var divHeight = parseInt(screenH * percentage / 100);
	//alert(divHeight);
	var tableH = parseInt(resultTable.offsetHeight);
	layer.style.height = tableH+6 > divHeight? divHeight : tableH +6;
	layer.style.overflow = "auto";
	return;
}
	

function check(a_id,b_id) {
aObj = document.getElementById(a_id);
bObj = document.getElementById(b_id);
if (aObj.checked) {bObj.disabled=false}
else {bObj.checked=false;bObj.disabled=true};
}


function showLayer(number,mymodal){
   var mask = document.getElementById("mask");
   mask.style.display = "";
   //mask.style.width = document.documentElement.clientWidth + 10;
   //mask.style.left = "-10px";
   
	var Id_layer = "pop_layer_" + number;
	var Id_ifr = "pop_ifr_" + number;
	Obj_layer = document.getElementById(Id_layer);
	C_width = document.compatMode=="CSS1Compat" ? (document.documentElement.clientWidth - document.documentElement.scrollLeft) : (document.body.clientWidth - document.body.scrollLeft);
	C_height = document.compatMode=="CSS1Compat" ?  (document.documentElement.clientHeight) : (document.body.clientHeight); 
	C_top = document.compatMode=="CSS1Compat" ? (document.documentElement.scrollTop) : (document.body.scrollTop); 
	C_left = document.compatMode=="CSS1Compat" ? (document.documentElement.scrollLeft) : (document.body.scrollLeft); 
	//alert(mask.style.display);
	if(mymodal == 'modal' ){
		mask.style.display="none";}		
	
	Obj_layer.style.display = "";
	Obj_ifr = document.getElementById(Id_ifr);
	var L_width = Obj_layer.offsetWidth; 
	var L_height = Obj_layer.offsetHeight;
	Obj_ifr.height = L_height; 
	Obj_layer.style.left = C_left + (C_width - L_width)/2 +"px";
	Obj_layer.style.top = C_top + (C_height - L_height)/2 +"px";
	
	mask.style.height = document.body.scrollHeight;
}

function closeLayer(number){
	var Id_layer = "pop_layer_" + number;
	Obj_layer = document.getElementById(Id_layer);
	if (Obj_layer.style.display != "none")
		Obj_layer.style.display = "none"; 
		
   var mask = ui_getObjById("mask");
   mask.style.display = "none";	
}

//resize the position of pop_layer , make it keep in the middle in the Browser
function resizePoplayer()
{   
    var mask = document.getElementById("mask");
	mask.style.width = document.documentElement.clientWidth;
    mask.style.height = document.documentElement.clientHeight;

    //find the poplayer on display
	var Obj_layer;
	var test = document.getElementsByTagName("DIV");
	for(var temp =0;temp<test.length;temp++)
	{
		if(test[temp].style.display == "")
		Obj_layer=test[temp];	
	}
	
	if(parseInt(document.documentElement.clientWidth-Obj_layer.clientWidth)>0)
	{
        Obj_layer.style.left = Math.abs(document.documentElement.clientWidth-Obj_layer.clientWidth)/2+"px" ;   
	}
	else 
	{
	    Obj_layer.style.left = 0+"px";
		
	}
	if(parseInt(document.documentElement.clientHeight-Obj_layer.clientHeight)>0)
	{
	   Obj_layer.style.top = Math.abs(document.documentElement.clientHeight-Obj_layer.clientHeight)/2+"px" ;
	}
	else
	{
	Obj_layer.style.top = 0+"px";
	}  
	
}

//display content
function displayContent()
{
  ui_getObjById("content").style.visibility = "visible"; 
}

